home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / bisonpcb.zip / BISON.SIM < prev    next >
Text File  |  1987-02-11  |  12KB  |  439 lines

  1. #line 1 "bison.sim"
  2.  
  3. /* Skeleton output parser for bison,
  4.    copyright (C) 1984 Bob Corbett and Richard Stallman
  5.  
  6.    Permission is granted to anyone to make or distribute verbatim copies of this program
  7.    provided that the copyright notice and this permission notice are preserved;
  8.    and provided that the recipient is not asked to waive or limit his right to
  9.    redistribute copies as permitted by this permission notice;
  10.    and provided that anyone possessing an executable copy
  11.    is granted access to copy the source code, in machine-readable form,
  12.    in some reasonable manner.
  13.  
  14.    Permission is granted to distribute derived works or enhanced versions of
  15.    this program under the above conditions with the additional condition
  16.    that the entire derivative or enhanced work
  17.    must be covered by a permission notice identical to this one.
  18.  
  19.    Anything distributed as part of a package containing portions derived
  20.    from this program, which cannot in current practice perform its function usefully
  21.    in the absense of what was derived directly from this program,
  22.    is to be considered as forming, together with the latter,
  23.    a single work derived from this program,
  24.    which must be entirely covered by a permission notice identical to this one
  25.    in order for distribution of the package to be permitted.
  26.  
  27.  In other words, you are welcome to use, share and improve this program.
  28.  You are forbidden to forbid anyone else to use, share and improve
  29.  what you give them.   Help stamp out software-hoarding!  */
  30.  
  31. /* This is the parser code that is written into each bison parser
  32.   when the %semantic_parser declaration is not specified in the grammar.
  33.   It was written by Richard Stallman by simplifying the hairy parser
  34.   used when %semantic_parser is specified.  */
  35.  
  36. /* Note: there must be only one dollar sign in this file.
  37.    It is replaced by the list of actions, each action
  38.    as one case of the switch.  */
  39.  
  40. #include <malloc.h>    /* WG */
  41. #include <string.h>    /* WG */
  42.  
  43. #define yyerrok        (yyerrstatus = 0)
  44. #define yyclearin    (yychar = YYEMPTY)
  45. #define YYEMPTY        -2
  46. #define YYEOF        0
  47. #define YYFAIL        goto yyerrlab;
  48.  
  49. #define YYTERROR    1
  50.  
  51. #ifndef YYIMPURE
  52. #define YYLEX        yylex()
  53. int yylex(void);    /* WG */
  54. #endif
  55.  
  56. #ifndef YYPURE
  57. #define YYLEX        yylex(&yylval, &yylloc)
  58. int yylex(int, int);    /* WG */
  59. #endif
  60.  
  61. /* If nonreentrant, generate the variables here */
  62.  
  63. #ifndef YYIMPURE
  64.  
  65. int    yychar;            /*  the lookahead symbol        */
  66. YYSTYPE    yylval;            /*  the semantic value of the        */
  67.                 /*  lookahead symbol            */
  68.  
  69. YYLTYPE yylloc;            /*  location data for the lookahead    */
  70.                 /*  symbol                */
  71.  
  72. int yydebug = 0;        /*  nonzero means print parse trace    */
  73.  
  74. #endif  /* YYIMPURE */
  75.  
  76.  
  77. /*  YYMAXDEPTH indicates the initial size of the parser's stacks    */
  78.  
  79. #ifndef    YYMAXDEPTH
  80. #define YYMAXDEPTH 200
  81. #endif
  82.  
  83. /*  YYMAXLIMIT is the maximum size the stacks can grow to
  84.     (effective only if the built-in stack extension method is used).  */
  85.  
  86. #ifndef YYMAXLIMIT
  87. #define YYMAXLIMIT 10000
  88. #endif
  89.  
  90.  
  91. #line 91 "bison.sim"
  92. int
  93. yyparse()
  94. {
  95.   register int yystate;
  96.   register int yyn;
  97.   register short *yyssp;
  98.   register YYSTYPE *yyvsp;
  99.   void yyerror(char *);    /* WG */
  100.   YYLTYPE *yylsp;
  101.   int yyerrstatus;    /*  number of tokens to shift before error messages enabled */
  102.   int yychar1;        /*  lookahead token as an internal (translated) token number */
  103.  
  104.   short    yyssa[YYMAXDEPTH];    /*  the state stack            */
  105.   YYSTYPE yyvsa[YYMAXDEPTH];    /*  the semantic value stack        */
  106.   YYLTYPE yylsa[YYMAXDEPTH];    /*  the location stack            */
  107.  
  108.   short *yyss = yyssa;        /*  refer to the stacks thru separate pointers */
  109.   YYSTYPE *yyvs = yyvsa;    /*  to allow yyoverflow to reallocate them elsewhere */
  110.   YYLTYPE *yyls = yylsa;
  111.  
  112.   int yymaxdepth = YYMAXDEPTH;
  113.  
  114. #ifndef YYPURE
  115.  
  116.   int yychar;
  117.   YYSTYPE yylval;
  118.   YYLTYPE yylloc;
  119.  
  120.   extern int yydebug;
  121.  
  122. #endif
  123.  
  124.  
  125.   YYSTYPE yyval;        /*  the variable used to return        */
  126.                 /*  semantic values from the action    */
  127.                 /*  routines                */
  128.  
  129.   int yylen;
  130.  
  131.   if (yydebug)
  132.     fprintf(stderr, "Starting parse\n");
  133.  
  134.   yystate = 0;
  135.   yyerrstatus = 0;
  136.   yychar = YYEMPTY;        /* Cause a token to be read.  */
  137.  
  138.   /* Initialize stack pointers.
  139.      Waste one element of value and location stack
  140.      so that they stay on the same level as the state stack.  */
  141.  
  142.   yyssp = yyss - 1;
  143.   yyvsp = yyvs;
  144.   yylsp = yyls;
  145.  
  146. /* Push a new state, which is found in  yystate  .  */
  147. /* In all cases, when you get here, the value and location stacks
  148.    have just been pushed. so pushing a state here evens the stacks.  */
  149. yynewstate:
  150.  
  151.   *++yyssp = yystate;
  152.  
  153.   if (yyssp >= yyss + yymaxdepth - 1)
  154.     {
  155.       /* Give user a chance to reallocate the stack */
  156.       /* Use copies of these so that the &'s don't force the real ones into memory. */
  157.       YYSTYPE *yyvs1 = yyvs;
  158.       YYLTYPE *yyls1 = yyls;
  159.       short *yyss1 = yyss;
  160.  
  161.       /* Get the current used size of the three stacks, in elements.  */
  162.       int size = yyssp - yyss + 1;
  163.  
  164. #ifdef yyoverflow
  165.       /* Each stack pointer address is followed by the size of
  166.      the data in use in that stack, in bytes.  */
  167.       yyoverflow("parser stack overflow",
  168.          &yyss1, size * sizeof (*yyssp),
  169.          &yyvs1, size * sizeof (*yyvsp),
  170.          &yyls1, size * sizeof (*yylsp),
  171.          &yymaxdepth);
  172.  
  173.       yyss = yyss1; yyvs = yyvs1; yyls = yyls1;
  174. #else /* no yyoverflow */
  175.       /* Extend the stack our own way.  */
  176.       if (yymaxdepth >= YYMAXLIMIT)
  177.     yyerror("parser stack overflow");
  178.       yymaxdepth *= 2;
  179.       if (yymaxdepth > YYMAXLIMIT)
  180.     yymaxdepth = YYMAXLIMIT;
  181.       yyss = (short *) alloca (yymaxdepth * sizeof (*yyssp));
  182.       memcpy ((char *)yyss, (char *)yyss1, size * sizeof (*yyssp));    /* WG */
  183.       yyls = (YYLTYPE *) alloca (yymaxdepth * sizeof (*yylsp));
  184.       memcpy ( (char *)yyls, (char *)yyls1,size * sizeof (*yylsp));    /* WG */
  185.       yyvs = (YYSTYPE *) alloca (yymaxdepth * sizeof (*yyvsp));
  186.       memcpy ( (char *)yyvs, (char *)yyvs1, size * sizeof (*yyvsp));    /* WG */
  187. #endif /* no yyoverflow */
  188.  
  189.       yyssp = yyss + size - 1;
  190.       yylsp = yyls + size - 1;
  191.       yyvsp = yyvs + size - 1;
  192.  
  193.       if (yydebug)
  194.     fprintf(stderr, "Stack size increased to %d\n", yymaxdepth);
  195.  
  196.       if (yyssp >= yyss + yymaxdepth - 1)
  197.     YYERROR;
  198.     }
  199.  
  200.   if (yydebug)
  201.     fprintf(stderr, "Entering state %d\n", yystate);
  202.  
  203. /* Do appropriate processing given the current state.  */
  204. /* Read a lookahead token if we need one and don't already have one.  */
  205. yyresume:
  206.  
  207.   /* First try to decide what to do without reference to lookahead token.  */
  208.  
  209.   yyn = (int)yypact[yystate];    /* WG */
  210.   if (yyn == YYFLAG)
  211.     goto yydefault;
  212.  
  213.   /* Not known => get a lookahead token if don't already have one.  */
  214.  
  215.   /* yychar is either YYEMPTY or YYEOF
  216.      or a valid token in external form.  */
  217.  
  218.   if (yychar == YYEMPTY)
  219.     {
  220.       yychar = YYLEX;
  221.     }
  222.  
  223.   /* Convert token to internal form (in yychar1) for indexing tables with */
  224.  
  225.   if (yychar <= 0)        /* This means end of input. */
  226.     {
  227.       yychar1 = 0;
  228.       yychar = YYEOF;        /* Don't call YYLEX any more */
  229.  
  230.       if (yydebug)
  231.     fprintf(stderr, "Now at end of input.\n");
  232.     }
  233.   else
  234.     {
  235.       yychar1 = YYTRANSLATE(yychar);
  236.  
  237.       if (yydebug)
  238.     fprintf(stderr, "Parsing next token; it is %d (%s)\n", yychar, yytname[yychar1]);
  239.     }
  240.  
  241.   yyn += yychar1;
  242.   if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
  243.     goto yydefault;
  244.  
  245.   yyn = yytable[yyn];
  246.  
  247.   /* yyn is what to do for this token type in this state.
  248.      Negative => reduce, -yyn is rule number.
  249.      Positive => shift, yyn is new state.
  250.        New state is final state => don't bother to shift,
  251.        just return success.
  252.      0, or most negative number => error.  */
  253.  
  254.   if (yyn < 0)
  255.     {
  256.       if (yyn == (int)YYFLAG)    /* WG */
  257.     goto yyerrlab;
  258.       yyn = -yyn;
  259.       goto yyreduce;
  260.     }
  261.   else if (yyn == 0)
  262.     goto yyerrlab;
  263.  
  264.   if (yyn == YYFINAL)
  265.     YYACCEPT;
  266.  
  267.   /* Shift the lookahead token.  */
  268.  
  269.   if (yydebug)
  270.     fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]);
  271.  
  272.   /* Discard the token